home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3065 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  65 lines

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Is it possible to #include <#defined or -D 'ed macro>?
  5. Date: 25 Jan 1996 20:47:37 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Jan25134737@qcd.lanl.gov>
  8. References: <5rbuntgqp0.fsf@ritz.mordor.com> <4e8bbd$nl7@crl.crl.com>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: bobfry@crl.com's message of 25 Jan 1996 08:32:45 -0800
  13.  
  14. --text follows this line--
  15. In article <4e8bbd$nl7@crl.crl.com> bobfry@crl.com (Robert Fry) writes:
  16. <snip> 
  17.    benjamin@ritz.mordor.com (Joseph Thomas) writes:
  18.  
  19.    >Does anyone know a way of having an include statement that can include
  20.    >a file, based on a -D <MACRO_NAME> flag passed to the compiler, to
  21.    >give the effect of:
  22.  
  23.    >#include <SOURCE>
  24.  
  25.    >cc -D SOURCE=source_a.h
  26.  
  27.    >includes source_a.h
  28.  
  29.    >and 
  30.  
  31.    >cc -D SOURCE=source_b.h
  32.  
  33.    >includes source_b.h, (this doesn't seem to work with the xlc compiler)
  34.  
  35. Try 
  36.  
  37. #define STRIG(X) #X
  38. #define STR(X) STRING(X)
  39.  
  40. #include STR(SOURCE)
  41.  
  42. Except for loose wording of the standard, if SOURCE is #defined as
  43. source_a.h, this is completely equivalent to #include "source_a.h". 
  44.  
  45. or
  46.  
  47. #define HEADER
  48. #include HEADER<SOURCE>
  49.  
  50. which maybe equivalent to #include <source_a.h>. I say maybe, because
  51. the standard requires the implementation to document how it interprets
  52. this line: and the documented interpretation need not be
  53. <source_a.h> (though, there is no reason why it should choose anything
  54. else.) 
  55.  
  56. Cheers
  57. Tanmoy
  58. --
  59. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  60. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  61. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  62. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  63. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  64. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  65.